<?php

include('../includes/smarty.php');
include_once('../config.php');

session_start();

$ADMIN = new Admin();
$EMPLOYER = new Employer();

if(isset($_SESSION["id"]))
{
	$row = $ADMIN->validate_admin_session($_SESSION["id"]);
	
	if($row)
	{	
		$ADMIN->update_lastvisit($_SESSION["id"]);
		
		if(empty($_POST))
		{
			$smarty->assign('message',		'');
			
			$smarty->assign('title', 		'Admin: Select a Company');
			$smarty->assign('path', 		$site);
			$smarty->assign('body', 		'main/admin/deleteCompany.tpl');
			$smarty->assign('companylist', 	$EMPLOYER->get_companies());
		
			$smarty->display('admin.tpl');
		}
		else
		{
			$companyID = $_POST["companyName"];	//posts company name
			$validPost = $companyID != '';
			
			if($validPost)
			{
				$companyInfo = $EMPLOYER->delete_company($companyID);
				$smarty->assign('message',		'Successfully Deleted the Company');
			}	
			else
			{
				$smarty->assign('message',		'Please select a company.');
			}
			$smarty->assign('title', 		'Admin: Select a Company');
			$smarty->assign('path', 		$site);
			$smarty->assign('body', 		'main/admin/deleteCompany.tpl');
			$smarty->assign('companylist', 	$EMPLOYER->get_companies());
		
			$smarty->display('admin.tpl');
		}
	}
		else
	{
		//	Kill the current session, and show the login screen.
		session_destroy();
		header('Location: ../admin/index.php');
	}
}